package edu.washington.cs.workflow.instrument;

import java.awt.event.ActionEvent;

import edu.washington.cs.workflow.util.Utils;

public class ExecTracer {
	
	public static ExecTracer tracer = new ExecTracer();
	
	private ExecTracer() {}

	public void traceMethodEntry(String methodSig, Object thiz) {
		Utils.debugPrintln("Type of receiver: " + thiz.getClass());
		Utils.debugPrintln("entry: " + methodSig + ", source obj: " + System.identityHashCode(thiz) + ", type: " + thiz.getClass());
		if(thiz instanceof ActionEvent) {
			Utils.debugPrintln("   source object: " + ((ActionEvent)thiz).getSource().getClass()
					+ ",  code: " + System.identityHashCode(((ActionEvent)thiz).getSource()));
		}
	}
	
	public void traceMethodExit(String methodSig, Object thiz) {
		Utils.debugPrintln("exit: " + methodSig + ", source obj: " + System.identityHashCode(thiz) + ", type: " + thiz.getClass());
		if(thiz instanceof ActionEvent) {
			Utils.debugPrintln("   source object: " + ((ActionEvent)thiz).getSource().getClass()
					+ ",  code: " + System.identityHashCode(((ActionEvent)thiz).getSource()));
		}
	}
	
	public void traceMethodExcepExit(String methodSig, Object thiz) {
		Utils.debugPrintln("excep exit: " + methodSig + ", source obj: " + System.identityHashCode(thiz) + ", type: " + thiz.getClass());
		if(thiz instanceof ActionEvent) {
			Utils.debugPrintln("   source object: " + ((ActionEvent)thiz).getSource().getClass()
					+ ",  code: " + System.identityHashCode(((ActionEvent)thiz).getSource()));
		}
	}
	
	public void traceValueReturning(String methodSig, Object receiver) {
		Utils.debugPrintln("value returning calling : " + methodSig + ",  receiver: " + receiver.getClass() +
				",  code: " + System.identityHashCode(receiver));
	}
	
	public void traceObject(Object obj) {
		Utils.debugPrintln("object id: " + System.identityHashCode(obj));
	}
}